package com.zzj.ziputil;

import android.os.Handler;
import android.util.Log;
import de.innosystec.unrar.Archive;
import de.innosystec.unrar.rarfile.FileHeader;
import java.io.File;
import java.io.FileOutputStream;
import net.lingala.zip4j.util.InternalZipConstants;

/* loaded from: classes2.dex */
public class RarArchiver extends BaseArchiver {
    @Override // com.zzj.ziputil.BaseArchiver
    public void doArchiver(File[] fileArr, String str) {
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v10 */
    /* JADX WARN: Type inference failed for: r0v11 */
    /* JADX WARN: Type inference failed for: r0v3 */
    /* JADX WARN: Type inference failed for: r0v4 */
    /* JADX WARN: Type inference failed for: r0v5 */
    /* JADX WARN: Type inference failed for: r0v6, types: [de.innosystec.unrar.Archive] */
    /* JADX WARN: Type inference failed for: r0v7, types: [de.innosystec.unrar.Archive] */
    /* JADX WARN: Type inference failed for: r0v8, types: [de.innosystec.unrar.Archive] */
    @Override // com.zzj.ziputil.BaseArchiver
    public void doUnArchiver(String str, String str2, String str3, final IArchiverListener iArchiverListener) {
        Runnable runnable;
        Handler handler;
        String trim;
        File file = new File(str);
        if (str2 == null || "".equals(str2)) {
            str2 = file.getParentFile().getPath();
        }
        char charAt = str2.charAt(str2.length() - 1);
        if (charAt != '/' && charAt != '\\') {
            str2 = str2 + File.separator;
        }
        String str4 = "unrar file to :" + str2;
        Log.d(this.TAG, str4);
        ?? r0 = str4;
        if (iArchiverListener != null) {
            Handler handler2 = this.mHandler;
            Runnable runnable2 = new Runnable() { // from class: com.zzj.ziputil.RarArchiver.1
                @Override // java.lang.Runnable
                public void run() {
                    iArchiverListener.onStartArchiver();
                }
            };
            handler2.post(runnable2);
            r0 = runnable2;
        }
        FileOutputStream fileOutputStream = null;
        try {
            try {
                r0 = new Archive(file);
                try {
                    final int size = r0.getFileHeaders().size();
                    Log.d(this.TAG, file.getAbsolutePath() + " total  :" + size);
                    for (final int i = 0; i < size; i++) {
                        FileHeader fileHeader = r0.getFileHeaders().get(i);
                        if (fileHeader.isUnicode()) {
                            trim = fileHeader.getFileNameW().trim();
                        } else {
                            trim = fileHeader.getFileNameString().trim();
                        }
                        File file2 = new File(str2, trim.replaceAll("\\\\", InternalZipConstants.ZIP_FILE_SEPARATOR));
                        if (fileHeader.isDirectory()) {
                            file2.mkdirs();
                        } else {
                            File parentFile = file2.getParentFile();
                            if (parentFile != null && !parentFile.exists()) {
                                parentFile.mkdirs();
                            }
                            Log.d(this.TAG, " file  :" + file2.getAbsolutePath());
                            if (!file2.exists()) {
                                FileOutputStream fileOutputStream2 = new FileOutputStream(file2);
                                try {
                                    try {
                                        r0.extractFile(fileHeader, fileOutputStream2);
                                    } catch (Throwable th) {
                                        th = th;
                                        fileOutputStream = fileOutputStream2;
                                        if (fileOutputStream != null) {
                                            try {
                                                fileOutputStream.close();
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        }
                                        if (r0 != 0) {
                                            try {
                                                r0.close();
                                            } catch (Exception e2) {
                                                e2.printStackTrace();
                                            }
                                        }
                                        if (iArchiverListener != null) {
                                            this.mHandler.post(new Runnable() { // from class: com.zzj.ziputil.RarArchiver.3
                                                @Override // java.lang.Runnable
                                                public void run() {
                                                    iArchiverListener.onEndArchiver();
                                                }
                                            });
                                        }
                                        throw th;
                                    }
                                } catch (Exception e3) {
                                    try {
                                        e3.printStackTrace();
                                    } catch (Exception e4) {
                                        e = e4;
                                        fileOutputStream = fileOutputStream2;
                                        e.printStackTrace();
                                        if (fileOutputStream != null) {
                                            try {
                                                fileOutputStream.close();
                                            } catch (Exception e5) {
                                                e5.printStackTrace();
                                            }
                                        }
                                        if (r0 != 0) {
                                            try {
                                                r0.close();
                                            } catch (Exception e6) {
                                                e6.printStackTrace();
                                            }
                                        }
                                        if (iArchiverListener != null) {
                                            handler = this.mHandler;
                                            runnable = new Runnable() { // from class: com.zzj.ziputil.RarArchiver.3
                                                @Override // java.lang.Runnable
                                                public void run() {
                                                    iArchiverListener.onEndArchiver();
                                                }
                                            };
                                            handler.post(runnable);
                                        }
                                        return;
                                    }
                                }
                                fileOutputStream2.close();
                                fileOutputStream = fileOutputStream2;
                            }
                        }
                        if (iArchiverListener != null) {
                            this.mHandler.post(new Runnable() { // from class: com.zzj.ziputil.RarArchiver.2
                                @Override // java.lang.Runnable
                                public void run() {
                                    String str5 = RarArchiver.this.TAG;
                                    Log.d(str5, (i + 1) + "   :" + size);
                                    iArchiverListener.onProgressArchiver(i + 1, size);
                                }
                            });
                        }
                    }
                    r0.close();
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (Exception e7) {
                            e7.printStackTrace();
                        }
                    }
                    try {
                        r0.close();
                    } catch (Exception e8) {
                        e8.printStackTrace();
                    }
                } catch (Exception e9) {
                    e = e9;
                }
            } catch (Exception e10) {
                e = e10;
                r0 = 0;
            } catch (Throwable th2) {
                th = th2;
                r0 = 0;
            }
            if (iArchiverListener != null) {
                handler = this.mHandler;
                runnable = new Runnable() { // from class: com.zzj.ziputil.RarArchiver.3
                    @Override // java.lang.Runnable
                    public void run() {
                        iArchiverListener.onEndArchiver();
                    }
                };
                handler.post(runnable);
            }
        } catch (Throwable th3) {
            th = th3;
        }
    }
}
